package org.jeecg.modules.app.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.jeecg.modules.app.entity.FoodCategory;
import org.jeecg.modules.app.entity.ShopInfo;
import org.jeecg.modules.app.entity.ShopInfoRemake;
import org.jeecg.modules.app.service.ShopInfoRemakeService;
import org.jeecg.modules.app.service.ShopService;
import org.jeecg.modules.app.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 李圳川
 * @version 1.0
 * @date 2022/6/13 22:27
 * @content
 */

@Api(tags="app商家信息")
@RestController
@RequestMapping("/schoolOrder/app/shop")
public class ShopController {


    @Autowired
    private ShopService shopService;

    @Autowired
    private ShopInfoRemakeService shopInfoRemakeService;

    /**
     * 商家信息查询
     * @param createBy
     * @return
     */
    @ApiOperation("app商家信息查询")
    @GetMapping("/findShopInfoByCreateBy")
    public Result<?> findShopInfoByCreateBy(String createBy){
        ShopInfo shopInfo = shopService.findShopInfoByCreateBy(createBy);
        if(shopInfo != null)
            return Result.success("200","查询成功",shopInfo);
        else
            return Result.error("500","查询失败，没有这个商家");
    }

    /**
     * 商家信息分页查询
     * @param pageNum
     * @param pageSize
     * @param search
     * @return
     */
    @ApiOperation("app分页查询商家信息")
    @GetMapping("/findShopByPage")
    public Result<?> findShopByPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                    @RequestParam(defaultValue = "10") Integer pageSize,
                                    @RequestParam(defaultValue = "") String search){
        Page<ShopInfo> shopPage = shopService.findShopByPage(pageNum,pageSize,search);
        //System.out.println(shopPage.getRecords().size());
        return Result.success("200","查询成功",shopPage);
    }

    /**
     * 查询该商家的评论
     *
     * @return
     */
    @ApiOperation("app分页查询商家信息")
    @GetMapping("/findShopRemakeById")
    public Result<?> findShopRemakeById(String id){
        //System.out.println(id);
        List<ShopInfoRemake> remakeList = shopInfoRemakeService.findShopInfoById(id);
        //System.out.println(remakeList);
        return Result.success("200","查询成功",remakeList);
    }
}
